<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\Db;
// 应用公共文件

function judgeLogin($user,$password){
    $time=14000;
    if($user=='admin'&&$password=='admin'){//管理员登录
        cookie('typeLogin',1,$time);
        $userData=array('name'=>'admin','username'=>'admin');
        $data=1;
    }else{
        $arr=Db::query("select id,department,FLocalNum,typeName,name from raCall_user where FLocalNum='{$user}' and password='{$password}'");
        $userArr=$arr[0];
        if(!empty($arr)){
            if($userArr['typeName']=='admin'){//管理员权限
                cookie('typeLogin',1,$time);
            }else{
                cookie('typeLogin',2,$time);
            }
            $data=1;

            //名称过滤
            $couuntStrArr=array('兼职','临时工');
            foreach($couuntStrArr as $key=>$value){
                $subCount=substr_count($userArr['name'],$value);
                if($subCount){
                    $userNmae=$userArr['FLocalNum'];break;
                }else{
                    $userNmae=$userArr['name'];
                }
            }
            
            $userData=array('name'=>$userArr['FLocalNum'],'username'=>$userNmae,'department'=>$userArr['department']);
        }else{
            $data=0;
        }
    }
    if($data){
        cookie('userData',$userData,$time);
    }
    return $data;
}
function judgeFLocalNum($name,$id=null,$arr=null,$department=null){//子管理员 查询分机范围
    $typeNname=$department;

    $selectStr="typeName='{$typeNname}'";
    if($id){
        $selectStr.="and FLocalNum='{$id}'";
    }
    $FLocaarr=Db::query("select id,FLocalNum from raCall_user where {$selectStr}");
    if(empty($FLocaarr)){
        return $FLocaarr;
    }


    if($arr){//数据过滤判断
        foreach($arr as $key=>$value){
            $i=0;
            foreach($FLocaarr as $k=>$v){
                if($v['FLocalNum']==$value['FLocalNum']){
                    $i=1;break;
                }
            }
            if($i==0){$arr[$key]=null;}
        }
    }
    $arr=array_filter($arr);
    return $arr;
    //return $FLocaarr;
}
function gc($name){
    return cookie($name);
}